package com.mine.distinctionteam.ui.unused;

import android.os.Handler;
import android.os.Looper;

import com.mine.distinctionteam.base.IView;
import com.mine.distinctionteam.bean.unused.UnUsedBean;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 *
 */
public class UnUsedPresenter implements UnUsedContract.Presenter {
    private UnUsedContract.View view;
    private UnUsedContract.Modle modle;

    public UnUsedPresenter(UnUsedContract.View view) {
        this.view = view;
        modle = new UnUsedModle();
    }


    @Override
    public void getUnUsed(Map<String, String> map) {
        modle.getUnUsed(map, new Callback<UnUsedBean>() {
            @Override
            public void onResponse(Call<UnUsedBean> call, Response<UnUsedBean> response) {
                final UnUsedBean bean = response.body();
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getUnUsedSucess(bean);
                    }
                });
            }

            @Override
            public void onFailure(Call<UnUsedBean> call, Throwable t) {
                view.getUnUsedFail("加载失败");
            }
        });
    }

    @Override
    public void detachView() {

    }

    @Override
    public void attachView(IView view) {

    }
}
